import request from "@/utils/request";
import {ApiMethodContants, type ListResultData, type Pagination, type ResultData} from "@/apis/base";

export interface BlogResult {
    id: number
    blogContent: string
    enable: boolean
    createDate: string
    updateDate: string
    blogTitle: string
    editorType: 1 | 2
    blogDesc?: ''
}

export interface BlogTagsResult {
    id?: number
    tagName: string
    tagDesc: string
    tagImg: string
    enable: boolean
    createDate: string | undefined
    updateDate: string | undefined
}
export interface addBlogTagsDto {
    tagName: string
    tagDesc: string
    tagImg: string
    enable: boolean
    createDate: string | undefined
    updateDate: string | undefined
}
export interface updateBlogTagsDto {
    id: number
    tagName: string
    tagDesc: string
    tagImg: string
    enable: boolean
    createDate: string | undefined
    updateDate: string | undefined
}
export interface addOrUpdateBlogDto {
    blogContent: string
    editorType: 1 | 2
    tagList: number[]
    coverUrl: string
    id?: number
    enable?: boolean
    blogTitle: string
}
export interface BlogTagsListItem extends BlogTagsResult {
    blogId: number
    tagId: number
    relationId: number
}

export interface BlogAndTagResult extends BlogResult {
    tagsList?: BlogTagsListItem[]
}

interface GetBlogTagsDto {
    key?: string
    enable?: boolean
}

export function getBlogTags(getBlogTagsDto: GetBlogTagsDto): Promise<ResultData<BlogTagsResult[]>> {
    return request.mainAxios({
        url: `/blogs/getTags`,
        params: {
            ...(getBlogTagsDto || {})
        },
        method: ApiMethodContants.GET
    })
}
export interface QueryBlogParams extends Pagination {
    key: string
}
// 文章内容
export function getBlogs(queryParams: QueryBlogParams): Promise<ResultData<ListResultData<BlogAndTagResult>>> {
    return request.mainAxios({
        url: `/blogs/getBlogs`,
        params: {
            ...queryParams
        },
        method: ApiMethodContants.GET
    })
}

export function getBlogContent(id: number):Promise<ResultData<BlogResult>> {
    return request.mainAxios({
        url: `/blogs/getBlogContent`,
        params: {
            id
        },
        method: ApiMethodContants.GET
    })
}

